package org.o14x.alpha.domain;

import java.io.File;

import org.eclipse.jface.viewers.TreeViewer;
import org.o14x.alpha.ui.views.folder.FolderView;

/**
 * A tab in the explorer.
 * 
 * @author Olivier DANGREAUX
 */
public class ExplorerTab {
	/**
	 * The current folder shown by this tab.
	 */
	private File folder;

	/**
	 * An identifier for this tab.
	 */
	private String id;

	/**
	 * The FolderView where this folder is displayed;
	 */
	private FolderView folderView;

	/**
	 * The TreeViewer associated with this tab.
	 */
	private TreeViewer explorerTreeViewer;

	/**
	 * The NavigationHistory associated with this tab.
	 */
	private NavigationHistory navigationHistory;

	/**
	 * Creates a new instance of ExplorerTab.
	 */
	public ExplorerTab() {
		navigationHistory = new NavigationHistory();
	}

	/**
	 * Navigates to the given directory.
	 * 
	 * @param directory A directory.
	 */
	public void navigate(File directory) {
		if (directory != null && directory.exists()) {
			navigationHistory.memorize(directory);
			setFolder(directory);
		}
	}

	/**
	 * Goes back in the history.
	 */
	public void goBack() {
		File directory = navigationHistory.back();
		if (directory != null) {
			setFolder(directory);
		}
	}
	
	/**
	 * Goes forward in the history.
	 */
	public void goNext() {
		File directory = navigationHistory.next();
		if (directory != null) {
			setFolder(directory);
		}
	}

	/**
	 * Returns the value of folder.
	 *
	 * @return The value of folder.
	 */
	public File getFolder() {
		return folder;
	}

	/**
	 * Sets the value of folder.
	 *
	 * @param folder The value of folder to set.
	 */
	private void setFolder(File folder) {
		this.folder = folder;
	}

	/**
	 * Returns the value of id.
	 *
	 * @return The value of id.
	 */
	public String getId() {
		return id;
	}

	/**
	 * Sets the value of id.
	 *
	 * @param id The value of id to set.
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * Returns the value of folderView.
	 *
	 * @return The value of folderView.
	 */
	public FolderView getFolderView() {
		return folderView;
	}

	/**
	 * Sets the value of folderView.
	 *
	 * @param folderView The value of folderView to set.
	 */
	public void setFolderView(FolderView folderView) {
		this.folderView = folderView;
	}

	/**
	 * Returns the value of explorerTreeViewer.
	 *
	 * @return The value of explorerTreeViewer.
	 */
	public TreeViewer getExplorerTreeViewer() {
		return explorerTreeViewer;
	}

	/**
	 * Sets the value of explorerTreeViewer.
	 *
	 * @param explorerTreeViewer The value of explorerTreeViewer to set.
	 */
	public void setExplorerTreeViewer(TreeViewer explorerTreeViewer) {
		this.explorerTreeViewer = explorerTreeViewer;
	}

	/**
	 * Returns the value of navigationHistory.
	 *
	 * @return The value of navigationHistory.
	 */
	public NavigationHistory getNavigationHistory() {
		return navigationHistory;
	}

	/**
	 * Sets the value of navigationHistory.
	 *
	 * @param navigationHistory The value of navigationHistory to set.
	 */
	public void setNavigationHistory(NavigationHistory navigationHistory) {
		this.navigationHistory = navigationHistory;
	}
}
